import { getUserInfo, getMyAsk } from "@/static/js/my.js";
export default {
  data() {
    return {
      userInfo: {},
      askList: [],
      isRefreshing: false, //界面下拉的状态
      listStatus: "noMore",
      query: {
        page: 1,
        pagesize: 10,
      },
    };
  },
  onLoad(e) {
    this.getAskList();
  },
  onShow() {
    this.getUserInfo();
  },
  methods: {
    //获取个人信息
    getUserInfo() {
      getUserInfo({}).then((res) => {
        let info = res.data;
        let interest = info.bio.substring(0, 55);
        this.userInfo = info;
        this.userInfo.interest = interest;
      });
    },
    //下拉刷新
    reload() {
      this.isRefreshing = true;
      this.query.page = 1;
      this.getAskList();
    },
    //更多
    loadMore() {
      if (this.listStatus == "more") {
        this.query.page++;
        this.getAskList();
      }
    },

    //我的提问列表
    getAskList() {
      this.listStatus = "loading";
      getMyAsk(this.query).then((res) => {
        if (res.code == 1) {
          if (this.query.page == 1) {
            this.askList = [];
          }
          let list = res.data.list;
          this.listStatus =
            list.length >= this.query.pagesize ? "more" : "noMore";
          this.askList.push(
            ...list.map((val) => ({
              title: val.title,
              quiz_nickname: val.quiz_nickname,
              add_time_text: val.add_time_text,
              quiz_avatar: val.quiz_avatar,
              id: val.id,
              status: val.status,
            }))
          );
          this.isRefreshing = false;
        }
      });
    },

    //去编辑的页面
    edit() {
      uni.navigateTo({
        url: "../homePage/edit",
      });
    },

    //去关注页面
    goFollow() {
      uni.navigateTo({
        url: "/pages/my/homeCenter/followList",
      });
    },

    //前往回答会话页面
    goInfo(item) {
      uni.navigateTo({
        url: "/quiz/askInfo/index?id=" + item.id,
      });
    },

    goBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
  },
};